function [vmax_v,cmax_v] = search_cr(aini,bini,q)
%SEARCH_Cr returns the best choice of c and v
%for retirees
amax=900;
bmax=4900;
global vfuture AMvalues BMvalues NCini crit r b eJr s climit
            cmin=climit;
            %insure afuture cannot be negative
            cmax=eJr+(1+r)*aini-tax(eJr+r*aini-q)-q;          
            cg=linspace(cmin,cmax,NCini);
            afuture=eJr+(1+r)*aini-tax(eJr+r*aini-q)-q-cg;
            bfuture=bini*(1+r)+q;
            vtemp=uc(cg)+b*s*interp2(AMvalues,BMvalues,vfuture,min(afuture,amax),min(bfuture,bmax),'spline',-1);
            [vtemp_v, ctemp_g]=max(vtemp);
            cmax_v=cg(ctemp_g);
            vmax_v=vtemp_v;            
            diff=(cmax-cmin)/4;
            while diff>crit

            diff=diff/2;
          
            if ((cmax_v>cmin))
                cg=cmax_v-diff;
            afuture=eJr+(1+r)*aini-tax(eJr+r*aini-q)-q-cg;
            vtemp=uc(cg)+b*s*interp2(AMvalues,BMvalues,vfuture,min(afuture,amax),min(bfuture,bmax),'spline',-1);
                if (vtemp>vmax_v) 
                    vmax_v=vtemp;
                    cmax_v=cg;
                    continue
                end %if
            end %while internal
            if ((cmax_v<cmax))
                cg=cmax_v+diff;
            afuture=eJr+(1+r)*aini-tax(eJr+r*aini-q)-q-cg;
            vtemp=uc(cg)+b*s*interp2(AMvalues,BMvalues,vfuture,min(afuture,amax),min(bfuture,bmax),'spline',-1);
                if (vtemp>vmax_v) 
                    vmax_v=vtemp;
                    cmax_v=cg;
                end %if
            end %while internal
            end %while
end

